package artid.com.arttogoa;

import org.apache.commons.lang3.StringUtils;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import artid.com.arttogoa.barcode.Cache;
import artid.com.arttogoa.parser.PersonalMessageParse;
import artid.com.arttogoa.util.AppUtil;
import artid.com.arttogoa.util.MySharedPreferences;
import artid.com.arttogoa.volley.VolleyBasic;
import artid.com.arttogoa.volley.VolleyCallback;
import artid.com.arttogoa.volley.VolleyData;
import artid.com.arttogoa.volley.VolleyMap;

import com.android.volley.VolleyError;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 项目名称：ArtworkArtA 类名称：PersonalMessageActivity 类描述：个人信息 创建人：耿卫斌 创建时间：2016年5月16日
 * 下午2:31:05
 */
public class PersonalMessageActivity extends BaseActivity implements
        OnClickListener {
    private TextView place, goodat, university, memo, name, classes_tv;
    private ImageView signatureChapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_message);
        setContent(this, getIntent());
        setBack();
        initView();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        PersonalMessage();
    }

    private void initView() {
        String Is_auth = AppUtil.getUser().getIs_auth();
        place = (TextView) findViewById(R.id.per_mess_place);
        goodat = (TextView) findViewById(R.id.per_mess_goodat);
        classes_tv = (TextView) findViewById(R.id.per_mess_classes);
        university = (TextView) findViewById(R.id.per_mess_university);
        memo = (TextView) findViewById(R.id.per_mess_memo);
        mTittle = (TextView) findViewById(R.id.title_text);
        mTittleRight = (TextView) findViewById(R.id.title_right);
        mTittleRight.setVisibility(View.VISIBLE);
        name = (TextView) findViewById(R.id.per_mess_name);
        signatureChapter = (ImageView) findViewById(R.id.personal_message_signatureChapter);
        mTittle.setText("个人信息");
        setBack();
        mTittleRight.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.title_right:
                Intent in = new Intent(PersonalMessageActivity.this,
                        EditMessageActivity.class);
                startActivity(in);
                break;
            default:
                break;
        }
    }

    /**
     * 获取个人信息
     */
    private void PersonalMessage() {
        VolleyBasic.getInstance(PersonalMessageActivity.this).post(
                Cache.editInformation,
                VolleyMap.getInstance().geteditInformation(),
                PersonalMessageParse.class, new VolleyCallback() {
                    @Override
                    public void onSuccess(VolleyData vd) {
                        Log.d("log", vd.toString());
                        PersonalMessageParse bean = (PersonalMessageParse) vd
                                .getData();
                        AppUtil.getUser().setAutograph(bean.getAutograph());
                        AppUtil.getUser().setMemo(bean.getMemo());
                        AppUtil.getUser().setUniversity(bean.getUniversity());
                        AppUtil.getUser().setNative_place(
                                bean.getNative_place());
                        AppUtil.getUser().setGood_at(bean.getGood_at());
                        AppUtil.getUser().setAutograph(bean.getAutograph());
                        ImageLoader.getInstance().displayImage(AppUtil.getUser().getAutograph(), signatureChapter);
                        place.setText(bean.getNative_place());
                        goodat.setText(bean.getGood_at());
                        university.setText(bean.getUniversity());
                        name.setText(AppUtil .getUser().getRealname());
                        memo.setText(bean.getMemo());
                        //分类,暂时先用本地数据
                        if (!StringUtils.isEmpty(MySharedPreferences.getMySharedPreferences(mContext).getValue("Classes" + AppUtil.getUser().getUid(), ""))) {
                            classes_tv.setText(MySharedPreferences.getMySharedPreferences(mContext).getValue("Classes" + AppUtil.getUser().getUid(), ""));
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {

                    }

                });
    }

}
